#include "key.h"
uint8_t key = 0, key1_state = 0, key2_state = 0, key1_count = 0, key2_count;
void key_scan(void)
{
    switch(key1_state) {
    case KEY_BEGIN :
        if(KEY1 == 0) {
            key1_state = KEY_CHECK;
            key1_count = 0;
        }
        break;
    case KEY_CHECK :
        if(KEY1 == 0) {
            key1_state = KEY_PRESS;
        } else {
            key1_state = KEY_BEGIN;
        }
        break;
    case KEY_PRESS :
        if(KEY1 == 0) {
            key1_count++;
        } else {
            if(key1_count <= SHORT_COUNT) {
                key = KEY1_SHORT;
            } else {
                key = KEY1_LONG;
            }
            key1_state = KEY_BEGIN;
        }
        break;
    default :
        key1_state = KEY_BEGIN;
        break;
    }

    switch(key2_state) {
    case KEY_BEGIN :
        if(KEY2 == 0) {
            key2_state = KEY_CHECK;
            key2_count = 0;
        }
        break;
    case KEY_CHECK :
        if(KEY2 == 0) {
            key2_state = KEY_PRESS;
        } else {
            key2_state = KEY_BEGIN;
        }
        break;
    case KEY_PRESS :
        if(KEY2 == 0) {
            key2_count++;
        } else {
            if(key2_count <= SHORT_COUNT) {
                key = KEY2_SHORT;
            } else {
                key = KEY2_LONG;
            }
            key2_state = KEY_BEGIN;
        }
        break;
    default :
        key2_state = KEY_BEGIN;
        break;
    }
}

